package com.nutiteq.labels;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import com.nutiteq.ui.Copyright;
import com.nutiteq.utils.Utils;

public class CustomCMCopyright implements Copyright {
  private final Image image;
  private final Font textFont = Font.getDefaultFont();
  private final int boxHeight;
  private final int boxWidth;
  private static final String COPYRIGHT = "© 2009 CloudMade";

  public CustomCMCopyright() {
    image = Utils.createImage("/cm-icon.png");

    boxHeight = Math.max(image.getHeight(), textFont.getHeight()) + 4;
    boxWidth = textFont.stringWidth(COPYRIGHT) + image.getWidth() + 4;
  }

  public void paint(final Graphics g, final int screenWidth, final int screenHeight) {
    g.setColor(0xFF000000);
    g.fillRoundRect(2, screenHeight - boxHeight - 3, boxWidth, boxHeight, 10, 10);
    g.setColor(0xFFFFFFFF);
    g.fillRoundRect(3, screenHeight - boxHeight - 2, boxWidth - 2, boxHeight - 2, 10, 10);
    g.setColor(0xFF000000);
    g.setFont(textFont);
    g.drawString(COPYRIGHT, 4, screenHeight - 4, Graphics.LEFT | Graphics.BOTTOM);
    g.drawImage(image, boxWidth, screenHeight - 5, Graphics.RIGHT | Graphics.BOTTOM);
  }
}
